package com.example.design.singleton;

/**
 * @ClassName Singleton7
 * @Description 静态内部类 Holder单例模式【推荐】
 * 线程安全性： 线程安全性
 * 是否懒加载： 懒加载
 * 性能： 性能好
 * @Author Administrator
 * @Date 2020/5/7 10:48
 * @Version 1.0
 */
public class Singleton7 {

    private Singleton7(){}

    public static Singleton7 getInstance(){
        return Holder.instance;
    }

    private static class Holder{
        private static Singleton7 instance = new Singleton7();
    }

    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public static void main(String[] args) {
        Singleton7 s1 = Singleton7.getInstance();
        Singleton7 s2 = Singleton7.getInstance();
        s1.setName("zhangsan7");
        s2.setName("lisi7");
        System.out.println(s1.getName());
        System.out.println(s2.getName());
        System.out.println(s1.getName().equals(s2.getName()));
    }

}
